package cn.wolfcode.luowowo.cloud.common.util;

import cn.wolfcode.luowowo.cloud.common.json.CodeMsg;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.io.Serializable;
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> implements Serializable {

    public static final Integer SUCCESS_CODE = 200;
    public static final String SUCCESS_MSG = "操作成功";
    public static final Integer ERROR_CODE = 50001;
    public static final String ERROR_MSG = "操作失败";
    private Integer code;
    private String msg;
    private T data;

    public static <T> Result success(String msg, T data){
        return new Result(SUCCESS_CODE, msg, data);
    }

    public static <T> Result success(T data){
        return new Result(SUCCESS_CODE, SUCCESS_MSG, data);
    }

    public static <T> Result success(){
        return new Result(SUCCESS_CODE, SUCCESS_MSG, null);
    }

    public static <T> Result error(CodeMsg codeMsg){
        return new Result(codeMsg.getCode(), codeMsg.getMsg(), null);
    }

    public static <T> Result defaultError(){
        return new Result(ERROR_CODE, ERROR_MSG, null);
    }
}
